package com.fenghongzhang.day005permission;

import androidx.annotation.NonNull;
import androidx.annotation.Px;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.os.Bundle;
import android.util.Log;

import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

public class MainActivity extends RxAppCompatActivity {


    private static final String TAG = "MainActivity";
    private RxPermissions rxPermissions = new RxPermissions(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Observable.interval(1, TimeUnit.SECONDS)
                .compose(this.<Long>bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        Log.i(TAG, "accept: "+aLong);
                    }
                });

//        requestPermissions(new String[]{});

//        rxPermissions.request(
//                 Manifest.permission.READ_EXTERNAL_STORAGE,
//                 Manifest.permission.WRITE_EXTERNAL_STORAGE,
//                 Manifest.permission.CALL_PHONE,
//                 Manifest.permission.INTERNET)
//           .subscribe(new Consumer<Boolean>() {
//            @Override
//            public void accept(Boolean aBoolean) throws Exception {
//                Log.i(TAG, "accept: "+aBoolean);
//            }
//        });
//
//        rxPermissions.requestEach(Manifest.permission.READ_EXTERNAL_STORAGE,
//                Manifest.permission.WRITE_EXTERNAL_STORAGE,
//                Manifest.permission.CALL_PHONE)
//                .subscribe(new Consumer<Permission>() {
//                    @Override
//                    public void accept(Permission permission) throws Exception {
//                        if(permission.granted){
//                            Log.i(TAG, "accept: 同意");
//                        }else if(permission.shouldShowRequestPermissionRationale){
//                            Log.i(TAG, "accept: 不同一");
//                        }else{
//                            Log.i(TAG, "accept: 一致不同意");
//                        }
//                    }
//                });



    }


}
